package com.dgut.crm.system.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.springframework.format.annotation.DateTimeFormat;

import com.dgut.crm.common.util.enumType.Sex;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="number")
public class Number {
	private Long id;
	
	private String userName; //用户名
	private String password; //需要加密
	private String realName; //真实名称
	private String email; //邮箱
	private String phone;
	private Sex sex;
	
	@DateTimeFormat(pattern="yyyy/MM/dd") 
	private Date birthday;
	
	private String address;
	private String idcard; //身份证
	
	@DateTimeFormat(pattern="yyyy/MM/dd") 
	private Date workTime; //工作时间
	private Integer workYear;
	
	private Department department;
	private List<Role> roles = new ArrayList<Role>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	
	@Column(length=20,unique=true,nullable=false)
	public String getUserName() {
		return userName;
	}
	
	@Column(length=20,nullable=false)
	public String getPassword() {
		return password;
	}

	@Column(length=10,nullable=true)
	public String getRealName() {
		return realName;
	}
	
	@Column(length=20,unique=true,nullable=true)
	public String getEmail() {
		return email;
	}
	
	@Column(length=15,nullable=true)
	public String getPhone() {
		return phone;
	}
	
	public Sex getSex() {
		return sex;
	}
	
	@JsonFormat(pattern = "yyyy/MM/dd",timezone = "GMT+8")
	@Temporal(TemporalType.DATE)
	public Date getBirthday() {
		return birthday;
	}

	@Column(length=30,nullable=true)
	public String getAddress() {
		return address;
	}

	@Column(length=18,nullable=true)
	public String getIdcard() {
		return idcard;
	}

	@JsonFormat(pattern = "yyyy/MM/dd",timezone = "GMT+8")
	@Temporal(TemporalType.DATE)
	public Date getWorkTime() {
		return workTime;
	}
	
	public Integer getWorkYear() {
		return workYear;
	}

	@JsonIgnore
	@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	public Department getDepartment() {
		return department;
	}
	
	@JsonIgnore
	@ManyToMany
	@JoinTable(name="number_role",
		joinColumns=@JoinColumn(name="number_id"),
		inverseJoinColumns=@JoinColumn(name="role_id")
	)
	public List<Role> getRoles() {
		return roles;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}

	public void setWorkTime(Date workTime) {
		this.workTime = workTime;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}
	
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public void setWorkYear(Integer workYear) {
		this.workYear = workYear;
	}

	public Number() {
	}

	public Number(Long id, String userName, String password, String realName, String email, String phone, Sex sex,
			Date birthday, String address, String idcard, Date workTime, Department department) {
		super();
		this.id = id;
		this.userName = userName;
		this.password = password;
		this.realName = realName;
		this.email = email;
		this.phone = phone;
		this.sex = sex;
		this.birthday = birthday;
		this.address = address;
		this.idcard = idcard;
		this.workTime = workTime;
		this.department = department;
	}

	@Override
	public String toString() {
		return "Number [id=" + id + ", userName=" + userName + ", password=" + password + ", realName=" + realName
				+ ", email=" + email + ", phone=" + phone + ", sex=" + sex + ", birthday=" + birthday + ", address="
				+ address + ", idcard=" + idcard + ", workTime=" + workTime + ", workYear=" + workYear + ", department="
				+ department + "]";
	}

	
}
